package com.mazegame.backend;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.shape.Rectangle;

public class ImageDisplayPane extends BorderPane {

    public ImageDisplayPane(String imageUrl, double width, double height,double radius) {
        ImageView imageView = new ImageView();
        try {
            Image image = new Image(imageUrl);
            imageView.setImage(image);
            imageView.setFitWidth(width);
            imageView.setFitHeight(height);
            //imageView.setPreserveRatio(false);
            // 设置最大宽高度
            imageView.setPreserveRatio(true);



            Rectangle clip = new Rectangle(imageView.getFitWidth(), imageView.getFitHeight());
            clip.setArcWidth(radius);
            clip.setArcHeight(radius);
            imageView.setClip(clip);

            setCenter(imageView);
        } catch (Exception e) {
            System.err.println("图片加载失败: " + imageUrl);
            // 设置空背景
            setStyle("-fx-background-color: #dddddd; -fx-background-radius: radius");
            setPrefSize(width, height);
        }
    }
}
